package com.ld.front.controller.dbtool;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ld.admin.model.system.dbtool.DbtoolColsModel;
import com.ld.common.controller.ProjectBasicController;
import com.ld.common.model.json.ApiResult;
import com.ld.shieldsb.dao.model.QueryModel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 数据库工具服务
 * 
 * @ClassName TimedTaskController
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2019年4月26日 上午11:04:24
 *
 */
@Api(tags = "数据库工具服务") // description 必填 文档显示 标题
@RestController
@RequestMapping("${shieldsb.frontPath}/dbtool")
public class DbtoolController extends ProjectBasicController<Object> {

    @ApiOperation(value = "获取系统列设置", notes = "") // value 必填文档显示
    @RequestMapping(path = "/getCols", method = RequestMethod.GET)
    // 返回json格式
    public ApiResult<List<DbtoolColsModel>> getCols(
            @ApiParam(name = "name", value = "列关键字(可以为中文名称)", required = true) @RequestParam String name)
            throws ServletException, IOException {
        name = name.trim();
        QueryModel queryModel = basicService.getNormalQueryModel();
        QueryModel queryModelOr1 = new QueryModel();
        queryModelOr1.addLike("columnName", name); // 列名
        QueryModel queryModelOr2 = new QueryModel();
        queryModelOr2.addLike("showName", name); // 中文名称
        QueryModel queryModelOr3 = new QueryModel();
        queryModelOr3.addLike("aliasName", name); // 中文别名
        queryModel.addOrMultiCondition(queryModelOr1, queryModelOr2, queryModelOr3);
        List<DbtoolColsModel> colsModels = basicService.getList(DbtoolColsModel.class, queryModel, 10);
        return ApiResult.ok(colsModels);
    }

}
